-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #3448] Create API endpoint for POST /users/:userID/save-searches #3472
base: main
Are you sure you want to change the base?
[Issue #3448] Create API endpoint for POST /users/:userID/save-searches #3472
Conversation
api/src/api/users/user_schemas.py
Outdated
search_query = fields.Dict( | ||
required=True, | ||
metadata={ | ||
"description": "The search query parameters to save", | ||
"example": {"keywords": "search", "location": "Foo, Bar"}, | ||
}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have this be the actual schema we use in the search endpoint? Just to make sure it's valid.
Also want to make sure the JSON serialization works with a full search request object for things like enums and dates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added something to the test using get_search_request()
. Something like this you have in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we would do search_query = fields.Nested(OpportunitySearchRequestV1Schema)
- that way we can only take in a schema that is valid for search. Anything that isn't a valid search request should be rejected (eg. a user couldn't just pass {"some_field": "whatever"}
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked in the changes. This makes me wonder if we should also store the version of the search request schema for validation later. If, for example, we want the response to correspond to the schema that was inputted. It would be able to handle schema changes (and we could just output a dict
response type validated against the stored schema version in a new db column. Otherwise we would not be able to validate response schema if this OpportunitySearchRequestV1Schema changes.
Co-authored-by: Michael Chouinard <[email protected]>
…ps://github.com/HHS/simpler-grants-gov into mikehgrantsgov/3448-create-save-search-endpoint
api/src/api/users/user_schemas.py
Outdated
search_query = fields.Dict( | ||
required=True, | ||
metadata={ | ||
"description": "The search query parameters to save", | ||
"example": {"keywords": "search", "location": "Foo, Bar"}, | ||
}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we would do search_query = fields.Nested(OpportunitySearchRequestV1Schema)
- that way we can only take in a schema that is valid for search. Anything that isn't a valid search request should be rejected (eg. a user couldn't just pass {"some_field": "whatever"}
.)
Co-authored-by: Michael Chouinard <[email protected]>
…ps://github.com/HHS/simpler-grants-gov into mikehgrantsgov/3448-create-save-search-endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one small change
with db_session.begin(): | ||
db_session.add(saved_search) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can exclude the begin here since we already began it in the route. Actually, in a lot of cases this would error with an "already started transaction error", guessing that didn't happen because you hadn't done any DB operations yet.
Summary
Fixes #3448
Time to review: 15 mins
Changes proposed
Add POST endpoint to create a saved search including routes and schemas.
Add supporting tests.
Context for reviewers
Supports the saved search requirements.
Additional information
See attached unit tests.